import request from "@/api/request.js";
import qs from "qs";
 
const baseUrl = '/cgi-bin'
 


//请求参数为json格式
 /**
  * 
  * @param {*} data 
  * {
  * name:Tbdzsbf.Yhyw*Tbdzsbf.Ehyw*Tbdzsbf.Zyl*Tbdzsbf.Whbyl*Tbdzsbf.Ssll*Tbdzsbf.Whplfk*Tbdzsbf.Whdlfk,
  * type:measure
  * }   
  * {
  * name:Tbdzsbf.Xyan*Tbdzsbf.Jtan*Tbdzsbf.Whbgpyxxhfk*Tbdzsbf.Whbgpgzxhfk*Tbdzsbf.Whbbpqyxfk*Tbdzsbf.Whbbpqgzfk*Tbdzsbf.Jsxh*Tbdzsbf.Jrxh*Tbdzsbf.Lxjbj*Tbdzsbf.Plcgkmxh*Tbdzsbf.Plcgddxh*Tbdzsbf.Whbjx*Tbdzsbf.Xtygz*Tbdzsbf.Yhywgbj*Tbdzsbf.Yhywdbj*Tbdzsbf.Ehywgbj*Tbdzsbf.Ehywdbj*Tbdzsbf.Whbylgbj*Tbdzsbf.Whbyldbj*Tbdzsbf.Zylgbj*Tbdzsbf.Zyldbj,
  * type:status
  * }
  * @returns 
  */
export function startGetListApi({name,type}) {
  return request({
    url: baseUrl + `/scada.cgi?names=${name}&type=${type}`,
    method: 'post',
    // data: data
  })
}

//注册追踪
/**
 * 
 * @param {*} data 
 * {
 * cmd:reg,
 * measureIdx:1*2*3,
 * },
 * {
 * cmd:reg,
 * statusIdx:1*2*3,
 * }
 * @returns 
 */
export function registerApi(data) {
    if(data.measureIdx!==null){
      return request({
        url: baseUrl + `/rts.cgi?cmd=${data.cmd}&measureIdx=${data.measureIdx}`,
        method: 'post',
      })
    }else if(data.statusIdx!==null){
      return request({
        url: baseUrl + `/rts.cgi?cmd=${data.cmd}&statusIdx=${data.statusIdx}`,
        method: 'post',
      })
    }
}
export function registerStatusApi(data) {
    return request({
      url: baseUrl + `/rts.cgi?cmd=${data.cmd}&statusIdx=${data.statusIdx}`,
      method: 'post',
    })
}


//轮询追踪
/**
 * 
 * @param {*} data 
 * {
 * cmd:query,
 * rtsm:29093E2CEB
 * 
 * }
 * @returns 
 */
export function pollApi({cmd,rtsm}) {
  return request({
    url: baseUrl + `/rts.cgi?cmd=${cmd}&rtsm=${rtsm}`,
    method: 'post'
  })
}

//login
export function loginApi({cmd,account,pwd}) {
  return request({
      url: baseUrl + `/account.cgi?cmd=${cmd}&account=${account}&pwd=${pwd}`,
      method: 'post',
      // data: qs.stringify({cmd,account,pwd}),
      headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' },
  })
}